In this video we will create forward looking portfolios and the simplest case is actually the two asset
to stark case and we are still imported the data from the last section.
So for example uh the returns data frame with the the daily returns for our six stocks and the market
portfolio.
And in this video we will focus on the Amazon and the Boeing stock and we created a new data frame two
assets and we can also calculate annualized the risk and return with the user defined function annualized
risk and return and actually be safe.
The summary data frame and the rabbi summary to and now in our next step we want to create a forward
looking portfolio where we have a 60 percent invested in the Amazon stock and 40 percent in the Boeing
stock.
So we create two new variables here and we put also 60 percent and 40 percent and a number higher rate
call it weights W S and now in a very first step we have to calculate the expected portfolio return
of our portfolio consisting of 60 percent Amazon and 40 percent Boeing and therefore we have to predict.
The expected return for Amazon and the we predict here 20 percent.
And we have to predict to the Boeing return the future Boeing return 15 percent and we can also save
those 2 in a panda series so here we are and actually calculating the expected return of our portfolios.
Pretty simple.
So we simply have to calculate uh the weighted average return and therefore we U.S.A.
The weight of Amazon times uh the expected return of Amazon plus the weight of Boeing times.
We expect that the return of Boeing.
And that's exactly what what we are doing here actually.
And uh we get actually the expected return of our portfolio and that is the 18 percent and actually
using this formula is a bit uncomfortable and that's a shortcut.
So we can simply use our a series the expected returns and we use the top method and pass our no higher
rate with our two rates here so that's a matrix multiplication and by doing so we calculate the evaded
average returns.
So here we get to exactly the same result 18 percent and now coming to the more difficult part calculating
the expected.
Portfolio risk and therefore on a very first step we create the covariance matrix of our two assets
and actually the annualized covariance matrix and we save the matrix and the rabbit covariance matrix
so that's an 8 to acid case pretty simple here.
So here we have the variance of the Amazon stock.
Then here we have the variance off of the Boeing stock.
And he and the diagonals we have actually the covariance between those two assets so we could actually
save the variance off the Amazon stock in the variable variance.
Amazon and it's here nine point six percent and the same we can do for the variance of the Boeing stock
and we can also save the covariance between Amazon and Boeing returns.
Also here in a new variable and it should be two point sixty one percent
and now we can calculate the expected risk of our portfolio by simply following the formula here.
So the expected risk of our portfolio is the square root.
And then within the square root we have here the squared the weight of our Amazon stock times.
The variance of the Amazon stock plus the squared weight of Boeing times the variance of uh Boeing stock
and then plus uh two times uh the weight of Amazon times.
The weight of Boeing times the covariance and let's have a look here and we get an expected risk in
standard deviation terms of twenty three point six percent.
And also here that's a pretty helpful shortcut.
So again we take the square root and then we use the covariance matrix and uh we apply here a matrix
multiplication with the top method and we pass uh the weights array and then we assign another matrix
multiplication with the weights array.
So let's uh running the shortcut and uh the results should actually be the same here.
So we get a standard deviation the expected standard deviation of uh twenty three point six percent.
And if you have some spare time you can also check and verify whether this is exactly the same as uh
this here or whether this leads here to the same formula.
So have fun to do so.
And that's actually here now.
The expected return and the expected risk of our forecast the portfolio.
So we have a risk of twenty three percent and a expected return of 18 percent.
So that's uh 1 Uh random or forward looking portfolio and we can also create many random portfolios
and let's assume we want to create 10000 the random portfolios with 10000 random weights.
Then we create here a matrix uh consisting of 10000 rows and two columns.
So 10000 portfolios.
And we have two weights and then we calculate the weights actually.
So here we have our 10000 portfolios.
So the first one for example consisting of seventy point eight percent Amazon and twenty nine point
one percent Boeing.
And then for all of these 10000 random portfolios we can calculate the expected return of these portfolios
by simply using here our panel serious was the expected returns of the two assets and applying the top
method and passing the transposed the weights matrix here.
So let's have a look.
So here we have the returns array consisting of 10000 expected returns for our 10000 random portfolios.
So for example the expected return of the very first portfolio is eighteen point five four percent.
And this is based on a portfolio consisting of seventy point eight percent Amazon stock and twenty nine
point one percent.
Boeing stock and the same we can do also for the risk.
So we take the square root here and within the square root.
This looks a little bit different.
So we have our covariance matrix.
Then we use the top method and pass the transposed weights matrix and then again we multiply with the
weights matrix and then we sum up all rows.
So let's run the cell.
And by doing so we should get the standard deviation of all 10000 random portfolios and we can all say
look here.
So for example the very first portfolio has a standard deviation of twenty five point two 2% and finally
we can also create a summary data frame with the first column.
The returns of the 10000 portfolios and as the second column the risk
so here we have a risk and return for our 10000 random portfolios
and of course we can also visualize them.
So we create a set up plot with on the x axis.
The risk column here and on the y axis the return column.
And we also plot.
We expect that risk and return for our two stocks.
So you see our summary.
To a data frame and take the risk and the expected returns actually of our two constituents and let's
have a look here
and here we have the expected risk and return for Boeing for Amazon and in red we have all possible
combinations of risk and return if we create the portfolios consisting of Amazon and Boeing.
So that's the two asset case and in the next video we will consider the more asset or many asset case
and hope to see there by.